//
//  HZLoginField.m
//  MyDoctor
//
//  Created by 黑眼圈 on 16/5/5.
//  Copyright © 2016年 heiyan. All rights reserved.
//

#import "HZLoginField.h"


@interface HZLoginField()

@property(nonatomic,strong)UIImageView*  icon;
@property(nonatomic,strong)UIButton*  btn;

@end


@implementation HZLoginField



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupUI];
    }
    return self;
}


-(void)setupUI{
    

    
    [self addSubview:self.icon];
    [self addSubview:self.btn];
    
    //约束
        [self.icon makeConstraints:^(MASConstraintMaker *make) {
    
            make.top.equalTo(6);
            make.bottom.equalTo(-6);
    
            make.leading.equalTo(10);
            make.width.equalTo(15);
        }];
        
    
    self.rightView = self.btn;
    
    //默认隐藏
    self.rightView.hidden = YES;
    
}

#pragma mark -
#pragma mark     懒加载子控件
-(UIImageView *)icon{
    if (!_icon) {
        
        _icon = [[UIImageView alloc]init];
        
        _icon.image = [UIImage imageNamed:@"product_img_icon_xieyi.png"];

    }
    return _icon;
}

-(UIButton *)btn{
    if (!_btn) {
        
        _btn = [[UIButton alloc]init];
        
        [_btn setBackgroundImage:[UIImage imageNamed:@"compose_photo_close"] forState:UIControlStateNormal];
        
        [_btn sizeToFit];
    }
    return _btn;
}



// 控制placeHolder的位置，左右缩20，但是光标位置不变

-(CGRect)placeholderRectForBounds:(CGRect)bounds
{
    CGRect inset = CGRectMake(bounds.origin.x+30, bounds.origin.y+2.5, bounds.size.width -10, bounds.size.height);
    return inset;
}


// 修改文本展示区域，一般跟editingRectForBounds一起重写
- (CGRect)textRectForBounds:(CGRect)bounds
{
    CGRect inset = CGRectMake(bounds.origin.x+10, bounds.origin.y, bounds.size.width-25, bounds.size.height);//更好理解些
    return inset;
}

// 重写来编辑区域，可以改变光标起始位置，以及光标最右到什么地方，placeHolder的位置也会改变
-(CGRect)editingRectForBounds:(CGRect)bounds
{
    CGRect inset = CGRectMake(bounds.origin.x+30, bounds.origin.y, bounds.size.width-25, bounds.size.height);//更好理解些
    return inset;
}


@end
